﻿Imports System.IO
Imports Operation
Imports Model
Imports Model.Geometry
Imports Model.Section
Imports Model.Midline
Imports Model.Result
Imports Helper

Public Class MyControlCircle

#Region "属性"
    Public ccp As New Project.MyProject()
    Public pp As New prepara()
    Public paralist As New ParaCircleTunnel()
    Public resultlist As New List(Of CircleResult)()
    Public pubpath = ""
    Public currtime As String
    Public flag = 0
    Public Millist As New List(Of Double)
#End Region

    ''' <summary>
    ''' 构造函数重载
    ''' </summary>
    ''' <param name="cp"></param>
    ''' <remarks></remarks>
    Public Sub New(ByRef cp As Project.MyProject)
        InitializeComponent()
        ccp = cp
        pubpath = ccp.ProDir + "\" + ccp.ProID + ccp.ProName
    End Sub
    ''' <summary>
    ''' 圆形隧道拟合计算界面加载事件
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub MyControlCircle_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        cbx_midline.Items.Add("隧道中线（平）.txt")
        cbx_Vline.Items.Add("隧道中线（竖）.txt")
        If ccp Is Nothing Then
            MsgBox("请打开或新建工程", , "提示")
            Return
        End If
        Dim num = ccp.ProMidLine.Count
        Dim num1 = ccp.ProPts.Count

        For i = 0 To num - 1
        Next
        For i = 0 To num1 - 1
            cbx_pts.Items.Add(ccp.ProPts(i))
        Next

        'MsgBox(Me.Parent.Parent.Parent.Parent.Controls(0).Controls(0).Name)

    End Sub

    ''' <summary>
    ''' 选择点云数据后进行解析
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cbx_pts_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbx_pts.SelectedIndexChanged
        Dim ptlist As New List(Of Point3d)()
        ptlist.Clear()
        Dim line(3) As String
        Dim temppt As New Point3d()
        Dim xmax As Double = -1000000
        Dim xmin As Double = 1000000
        Dim ymax As Double = -1000000
        Dim ymin As Double = 1000000
        Dim zmax As Double = -1000000
        Dim zmin As Double = 1000000
        Dim n = 0
        Dim sr As StreamReader = New StreamReader(cbx_pts.SelectedItem.ToString(), System.Text.Encoding.UTF8)
        Do While sr.Peek() > 0
            temppt = New Point3d()
            line = sr.ReadLine().Split(",")
            If line(0) = "" Then
                Continue Do
            End If
            temppt.p_x = Double.Parse(line(0))
            temppt.p_y = Double.Parse(line(1))
            temppt.p_z = Double.Parse(line(2))
            ptlist.Add(temppt)
            If temppt.p_x > xmax Then
                xmax = temppt.p_x
            End If
            If temppt.p_x < xmin Then
                xmin = temppt.p_x
            End If
            If temppt.p_y > ymax Then
                ymax = temppt.p_y
            End If
            If temppt.p_y < ymin Then
                ymin = temppt.p_y
            End If
            If temppt.p_z > zmax Then
                zmax = temppt.p_z
            End If
            If temppt.p_z < zmin Then
                zmin = temppt.p_z
            End If
            n = n + 1
        Loop
        sr.Close()
        sr = Nothing

        totalpt.Text = n.ToString()
        Me.xmax.Text = Math.Round(xmax, 3).ToString()
        Me.xmin.Text = Math.Round(xmin, 3).ToString()
        Me.ymax.Text = Math.Round(ymax, 3).ToString()
        Me.ymin.Text = Math.Round(ymin, 3).ToString()
        Me.zmax.Text = Math.Round(zmax, 3).ToString()
        Me.zmin.Text = Math.Round(zmin, 3).ToString()

        paralist.Pts = ptlist
    End Sub

    Private Sub unprint_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles unprint.CheckedChanged
        paralist.DrawToCad = Not unprint.Checked
    End Sub

    Private Sub print_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles print.CheckedChanged
        paralist.DrawToCad = print.Checked
    End Sub
    ''' <summary>
    ''' 选择平曲线后进行解析
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cbx_midline_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbx_midline.SelectedIndexChanged
        Dim paraml As New List(Of Object)
        cbx_midline.Tag = pubpath + "\midline\" + cbx_midline.SelectedItem
        Dim i = 0
        Dim tempL As New Mid_Line()
        Dim tempC As New Mid_Circle()
        Dim tempSC As New Mid_SuperCircle()
        paraml.Clear()
        If ccp.ProMidLine.Count > 0 Then
            For i = 0 To ccp.ProMidLine.Count - 1
                tempL = New Mid_Line()
                tempC = New Mid_Circle()
                tempSC = New Mid_SuperCircle()
                If ccp.ProMidLine(i).LineType = LineTypeList.TypeLINE Then
                    ccp.ProMidLine(i).ConToL(tempL)
                    paraml.Add(tempL)
                    pp.numHL_L += 1
                ElseIf ccp.ProMidLine(i).LineType = LineTypeList.TypeCIRCLE Then
                    ccp.ProMidLine(i).ConToC(tempC)
                    paraml.Add(tempC)
                    pp.numHL_C += 1
                Else
                    ccp.ProMidLine(i).ConToSC(tempSC)
                    paraml.Add(tempSC)
                    pp.numHL_SC += 1
                End If
            Next
        End If
        For i = 0 To paraml.Count - 1
            If paraml(i).LineType = LineTypeList.TypeCIRCLE Then
                paraml(i).initMyself(paraml(i - 1))
            ElseIf paraml(i).LineType = LineTypeList.TypeSUPERCIRCLE Then
                'If (i + 1) = paraml.Count Then
                '    Return

                Dim a As Mid_SuperCircle = paraml(i)
                a.initMyself(paraml(i - 1))
                paraml(i).initMyself(paraml(i - 1))
            End If

        Next
        txt_numHL_L.Text = pp.numHL_L
        txt_numHL_C.Text = pp.numHL_C
        txt_numHL_SC.Text = pp.numHL_SC
        paralist.Hmidline = paraml
        'MsgBox(cbx_midline.Tag.ToString())
    End Sub
    ''' <summary>
    ''' 选择竖曲线后进行解析
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cbx_Vline_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbx_Vline.SelectedIndexChanged
        cbx_Vline.Tag = pubpath + "\midline\" + cbx_Vline.SelectedItem
        For i = 0 To ccp.VLine.bpdlist.Count - 1
            ccp.VLine.bpdlist(i).initMySelf()
        Next
        pp.numVL_BP = ccp.VLine.bpdlist.Count
        For j = 0 To pp.numVL_BP - 1
            If ccp.VLine.bpdlist(j).aotu = -1 Then
                pp.numVL_TU += 1
            Else
                pp.numVL_AO += 1
            End If
        Next
        allbpd.Text = pp.numVL_BP.ToString()
        aonum.Text = pp.numVL_AO.ToString()
        tunum.Text = pp.numVL_TU.ToString()
        paralist.Vmidline = ccp.VLine
    End Sub
    ''' <summary>
    ''' 预计断面结果
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Valuate_Click(sender As System.Object, e As System.EventArgs) Handles Valuate.Click
        Dim startNUM = 0, endNUM = 0
        pp.numSE_LS = 0
        pp.numSE_CS = 0
        pp.numSE_SCS = 0
        If paralist.CanUse() Then
            If paralist.StartMIL <= paralist.Hmidline(0).startm Then
                startNUM = 0
                paralist.StartMIL = paralist.Hmidline(0).endm
            End If
            If paralist.EndMIL = 0 Then
                endNUM = paralist.Hmidline.Count - 1
            End If
            For i = 0 To paralist.Hmidline.Count - 1
                If paralist.StartMIL < paralist.Hmidline(i).endm And paralist.StartMIL > paralist.Hmidline(i).startm Then
                    startNUM = i
                    Exit For
                End If
            Next
            For i = 0 To paralist.Hmidline.Count - 1
                If paralist.EndMIL < paralist.Hmidline(i).endm And paralist.EndMIL > paralist.Hmidline(i).startm Then
                    endNUM = i
                    Exit For
                End If
            Next

            If (startNUM = endNUM) Then
                If paralist.Hmidline(startNUM).LineType = LineTypeList.TypeLINE Then
                    pp.numSE_LS += Math.Truncate((paralist.EndMIL - paralist.StartMIL) / paralist.dist_L)
                ElseIf paralist.Hmidline(startNUM).LineType = LineTypeList.TypeCIRCLE Then
                    pp.numSE_CS += Math.Truncate((paralist.EndMIL - paralist.StartMIL) / paralist.dist_C)
                Else
                    pp.numSE_SCS += Math.Truncate((paralist.EndMIL - paralist.StartMIL) / paralist.dist_SC)
                End If

            Else

                If paralist.Hmidline(startNUM).LineType = LineTypeList.TypeLINE Then
                    pp.numSE_LS += Math.Truncate((paralist.Hmidline(startNUM).endm - paralist.StartMIL) / paralist.dist_L)
                ElseIf paralist.Hmidline(startNUM).LineType = LineTypeList.TypeCIRCLE Then
                    pp.numSE_CS += Math.Truncate((paralist.Hmidline(startNUM).endm - paralist.StartMIL) / paralist.dist_C)
                Else
                    pp.numSE_SCS += Math.Truncate((paralist.Hmidline(startNUM).endm - paralist.StartMIL) / paralist.dist_SC)
                End If

                If paralist.Hmidline(endNUM).LineType = LineTypeList.TypeLINE Then
                    pp.numSE_LS += Math.Truncate((paralist.EndMIL - paralist.Hmidline(endNUM).startm) / paralist.dist_L)
                ElseIf paralist.Hmidline(endNUM).LineType = LineTypeList.TypeCIRCLE Then
                    pp.numSE_CS += Math.Truncate((paralist.EndMIL - paralist.Hmidline(endNUM).startm) / paralist.dist_C)
                Else
                    pp.numSE_SCS += Math.Truncate((paralist.EndMIL - paralist.Hmidline(endNUM).startm) / paralist.dist_SC)
                End If

                For j = startNUM + 1 To endNUM - 1
                    If paralist.Hmidline(j).LineType = LineTypeList.TypeLINE Then
                        pp.numSE_LS += Math.Truncate((paralist.Hmidline(j).endm - paralist.Hmidline(j).startm) / paralist.dist_L)
                    ElseIf paralist.Hmidline(j).LineType = LineTypeList.TypeCIRCLE Then
                        pp.numSE_CS += Math.Truncate(paralist.Hmidline(j).length / paralist.dist_C)
                    Else
                        pp.numSE_SCS += Math.Truncate(paralist.Hmidline(j).length / paralist.dist_SC)
                    End If
                Next
            End If
            pp.numSE_AllS = pp.numSE_LS + pp.numSE_CS + pp.numSE_SCS
            SE_LS.Text = pp.numSE_LS.ToString()
            SE_CS.Text = pp.numSE_CS.ToString()
            SE_SCS.Text = pp.numSE_SCS.ToString()
            SE_AllS.Text = pp.numSE_AllS.ToString()

            paralist.startNUM = startNUM
            paralist.endNUM = endNUM
        Else
            MsgBox("请将参数填写完整", , "提示")
        End If
    End Sub

    Private Sub dist_L_TextChanged(sender As System.Object, e As System.EventArgs) Handles dist_L.TextChanged
        Dim Tvalue As Double
        If dist_L.Text <> "" Then
            If Double.TryParse(dist_L.Text, Tvalue) Then
                paralist.dist_L = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.dist_L = 0
        End If
    End Sub

    Private Sub dist_C_TextChanged(sender As System.Object, e As System.EventArgs) Handles dist_C.TextChanged
        Dim Tvalue As Double
        If dist_C.Text <> "" Then
            If Double.TryParse(dist_C.Text, Tvalue) Then
                paralist.dist_C = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.dist_C = 0
        End If
    End Sub

    Private Sub dist_SC_TextChanged(sender As System.Object, e As System.EventArgs) Handles dist_SC.TextChanged
        Dim Tvalue As Double
        If dist_SC.Text <> "" Then
            If Double.TryParse(dist_SC.Text, Tvalue) Then
                paralist.dist_SC = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.dist_SC = 0
        End If
    End Sub

    Private Sub width_L_TextChanged(sender As System.Object, e As System.EventArgs) Handles width_L.TextChanged
        Dim Tvalue As Double
        If width_L.Text <> "" Then
            If Double.TryParse(width_L.Text, Tvalue) Then
                paralist.width_L = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.width_L = 0
        End If
    End Sub

    Private Sub width_C_TextChanged(sender As System.Object, e As System.EventArgs) Handles width_C.TextChanged
        Dim Tvalue As Double
        If width_C.Text <> "" Then
            If Double.TryParse(width_C.Text, Tvalue) Then
                paralist.width_C = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.width_C = 0
        End If
    End Sub

    Private Sub width_SC_TextChanged(sender As System.Object, e As System.EventArgs) Handles width_SC.TextChanged
        Dim Tvalue As Double
        If width_SC.Text <> "" Then
            If Double.TryParse(width_SC.Text, Tvalue) Then
                paralist.width_SC = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.width_SC = 0
        End If
    End Sub

    Private Sub StartMIL_TextChanged(sender As System.Object, e As System.EventArgs) Handles StartMIL.TextChanged
        Dim Tvalue As Double
        If StartMIL.Text <> "" Then
            If Double.TryParse(StartMIL.Text, Tvalue) Then
                paralist.StartMIL = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.StartMIL = 0
        End If
    End Sub

    Private Sub EndMIL_TextChanged(sender As System.Object, e As System.EventArgs) Handles EndMIL.TextChanged
        Dim Tvalue As Double
        If EndMIL.Text <> "" Then
            If Double.TryParse(EndMIL.Text, Tvalue) Then
                paralist.EndMIL = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.EndMIL = 0
        End If
    End Sub

    Private Sub YesReport_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles YesReport.CheckedChanged
        If YesReport.Checked = True Then
            paralist.Report = True
        Else
            paralist.Report = False
        End If
    End Sub

    Private Sub NoReport_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles NoReport.CheckedChanged
        If NoReport.Checked = True Then
            paralist.Report = False
        Else
            paralist.Report = True
        End If
    End Sub
    ''' <summary>
    ''' 设置顶轨高
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtDingGG_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtDingGG.TextChanged
        Dim Tvalue As Double
        If txtDingGG.Text <> "" Then
            If Double.TryParse(txtDingGG.Text, Tvalue) Then
                paralist.DingGG = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.DingGG = 0
        End If
    End Sub
    ''' <summary>
    ''' 设置底轨高
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub txtDiGG_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtDiGG.TextChanged
        Dim Tvalue As Double
        If txtDiGG.Text <> "" Then
            If Double.TryParse(txtDiGG.Text, Tvalue) Then
                paralist.DiGG = Tvalue
            Else
                MsgBox("请输入一个小数", , "提示")
            End If
        Else
            paralist.DiGG = 0
        End If
    End Sub
    Public Sub GetMntListBylist(temp_mnt, mntlist)
        For i = 0 To Millist.Count - 1
            For j = 0 To paralist.Hmidline.Count - 1
                If Millist(i) <= paralist.Hmidline(j).endm And Millist(i) >= paralist.Hmidline(j).startm Then
                    temp_mnt = New ml_num_type()
                    temp_mnt.ml = Millist(i)
                    temp_mnt.num = j
                    Select Case paralist.Hmidline(j).LineType
                        Case LineTypeList.TypeLINE
                            temp_mnt.type = 0
                        Case LineTypeList.TypeCIRCLE
                            temp_mnt.type = 1
                        Case LineTypeList.TypeSUPERCIRCLE
                            temp_mnt.type = 2
                    End Select
                    mntlist.Add(temp_mnt)
                    Exit For
                End If
            Next
        Next
    End Sub

    ''' <summary>
    ''' 执行断面拟合提取算法
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Excute_Click(sender As System.Object, e As System.EventArgs) Handles Excute.Click
        ''单个结果，方便结果集的添加
        Dim temp_CR As New CircleResult()
        Dim temp_mnt As New ml_num_type()
        Dim mntlist As New List(Of ml_num_type)()
        Dim temp_pt As Point3d
        'Dim bbbb As Mid_SuperCircle = paralist.Hmidline(3)

        Label29.Visible = True
        Label30.Visible = True
        Label31.Visible = True
        Label32.Visible = True
        Label33.Visible = True
        Label34.Visible = True
        Label35.Visible = True
        Label36.Visible = True
        '''''''''''''''''''''''''''''''''''''''''''''''''''''测试代码''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'Dim vvv As New Point3d()
        'vvv = bbbb.GetPointByMileage(45094.066, New SingleVector())
        'MsgBox(vvv.p_x.ToString() + "," + vvv.p_y.ToString())
        'Return
        '''''''''''''''''''''''''''''''''''''''''''''''''''''测试代码''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        resultlist.Clear()
        If flag = 0 Then
            GetMntList(temp_mnt, mntlist)
        Else
            GetMntListBylist(temp_mnt, mntlist)
        End If

        For i = 0 To mntlist.Count - 1
            'Threading.Thread.Sleep(3000)
           
            
            temp_CR = New CircleResult()
            temp_CR.mileage = mntlist(i).ml
            temp_CR.stand_ele = paralist.Vmidline.GetEleByMileage(temp_CR.mileage)
            temp_CR.true_ptlist.Clear()

            Label32.Text = temp_CR.standmil()
            Label32.Refresh()
            Label33.Text = "正在拟合第" + (i + 1).ToString() + "个断面"
            Label33.Refresh()
            Label35.Text = Math.Round((i + 1) * 100 / mntlist.Count).ToString()
            Label35.Refresh()
            ProgressBar1.Value = Math.Round((i + 1) * 100 / mntlist.Count)

            Select Case mntlist(i).type
                Case 0
                    ''设置进度条曲线段类型
                    Label30.Text = "直线"
                    Label30.Refresh()
                    

                    temp_CR.Vec = paralist.Hmidline(mntlist(i).num).startOri
                    temp_CR.design_center = paralist.Hmidline(mntlist(i).num).GetPointByMileage(temp_CR.mileage)
                    temp_CR.pl = paralist.Hmidline(mntlist(i).num).GetPlaneByPoint(temp_CR.design_center)
                    For j = 0 To paralist.Pts.Count - 1
                        If (Section.PointToPlane(temp_CR.pl, paralist.Pts(j)) <= paralist.width_L / 2) Then
                            temp_pt = New Point3d()
                            temp_pt = Section.ProjectionToPlane(temp_CR.pl, paralist.Pts(j))
                            temp_CR.true_ptlist.Add(temp_pt)
                        End If
                    Next
                    Section.SimpleCoord(paralist.Hmidline(mntlist(i).num), temp_CR.design_center, temp_CR.true_ptlist, temp_CR.false_ptlist)
                    Section.LS_CircleFitting(temp_CR.false_ptlist, temp_CR.fitcircle)
                    temp_CR.suvery_center = Section.GetTrueCoord(temp_CR.Vec, temp_CR.fitcircle.center, temp_CR.design_center)

                Case 1
                    ''设置进度条曲线段类型
                    Label30.Text = "圆曲线"
                    Label30.Refresh()
                    

                    Dim mc As Mid_Circle = paralist.Hmidline(mntlist(i).num)
                    temp_CR.design_center = mc.GetPointByMileage(temp_CR.mileage, temp_CR.Vec)
                    temp_CR.pl = Section.GetPlane(temp_CR.design_center, temp_CR.Vec)
                    For j = 0 To paralist.Pts.Count - 1
                        If (Section.PointToPlane(temp_CR.pl, paralist.Pts(j)) <= paralist.width_C / 2) Then
                            temp_pt = New Point3d()
                            temp_pt = Section.ProjectionToPlane(temp_CR.pl, paralist.Pts(j))
                            temp_CR.true_ptlist.Add(temp_pt)
                        End If
                    Next
                    Section.SimpleCoord(temp_CR.Vec, temp_CR.design_center, temp_CR.true_ptlist, temp_CR.false_ptlist)

                    Section.LS_CircleFitting(temp_CR.false_ptlist, temp_CR.fitcircle)
                    temp_CR.suvery_center = Section.GetTrueCoord(temp_CR.Vec, temp_CR.fitcircle.center, temp_CR.design_center)

                Case Else
                    ''设置进度条曲线段类型
                    Label30.Text = "缓和曲线"
                    Label30.Refresh()

                    temp_CR.design_center = paralist.Hmidline(mntlist(i).num).GetPointByMileage(temp_CR.mileage, temp_CR.Vec)
                    temp_CR.pl = Section.GetPlane(temp_CR.design_center, temp_CR.Vec)
                    For j = 0 To paralist.Pts.Count - 1
                        If (Section.PointToPlane(temp_CR.pl, paralist.Pts(j)) <= paralist.width_SC / 2) Then
                            temp_pt = New Point3d()
                            temp_pt = Section.ProjectionToPlane(temp_CR.pl, paralist.Pts(j))
                            temp_CR.true_ptlist.Add(temp_pt)
                        End If
                    Next
                    Section.SimpleCoord(temp_CR.Vec, temp_CR.design_center, temp_CR.true_ptlist, temp_CR.false_ptlist)
                    Section.LS_CircleFitting(temp_CR.false_ptlist, temp_CR.fitcircle)
                    temp_CR.suvery_center = Section.GetTrueCoord(temp_CR.Vec, temp_CR.fitcircle.center, temp_CR.design_center)

            End Select
            ''获得最大最小高程''
            temp_CR.maxpt.p_x = temp_CR.fitcircle.center.p_x
            temp_CR.maxpt.p_y = temp_CR.fitcircle.center.p_y + temp_CR.fitcircle.radius
            temp_CR.maxpt.p_z = 0
            temp_CR.minpt.p_x = temp_CR.fitcircle.center.p_x
            temp_CR.minpt.p_y = temp_CR.fitcircle.center.p_y - temp_CR.fitcircle.radius
            temp_CR.minpt.p_z = 0
            temp_CR.max_ele = temp_CR.maxpt.p_y
            temp_CR.min_ele = temp_CR.minpt.p_y
            temp_CR.standmil()
            temp_CR.design_max = temp_CR.stand_ele + paralist.DingGG
            temp_CR.design_min = temp_CR.stand_ele - paralist.DiGG
            resultlist.Add(temp_CR)
        Next

        Label29.Text = "正在保存断面数据..."
        Label30.Visible = False
        Label31.Visible = False
        Label32.Visible = False
        Label33.Visible = False
        Label34.Visible = False
        Label35.Visible = False
        Label36.Visible = False

        currtime = DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒")
        outputpts(resultlist, pubpath, currtime, ProgressBar1)
        MsgBox("保存完成", , "提示")
        If paralist.DrawToCad = True Then

            Label29.Text = "正在使用CAD绘制断面图..."
            Label30.Visible = False
            Label31.Visible = False
            Label32.Visible = False
            Label33.Visible = False
            Label34.Visible = False
            Label35.Visible = False
            Label36.Visible = False

            Apply.DrawCircleResultToCAD(resultlist, ProgressBar1, pubpath, currtime)
            MsgBox("绘制完成", , "提示")
        End If

        If paralist.Report = True Then

            Label29.Text = "正在生成检测结果表..."
            Label30.Visible = False
            Label31.Visible = False
            Label32.Visible = False
            Label33.Visible = False
            Label34.Visible = False
            Label35.Visible = False
            Label36.Visible = False

            Apply.WriteDataToExcel(resultlist, ProgressBar1, pubpath, currtime)
            MsgBox("报表完成", , "提示")
        End If
        
        PATHHelper.addResultTreeView(Me.Parent.Parent.Parent.Parent.Controls(0).Controls(0), resultlist, True, True, currtime)
        'MsgBox(resultlist(0).suvery_center.p_x.ToString() + "," + resultlist(0).suvery_center.p_y.ToString() + "," + resultlist(0).min_ele.ToString())
    End Sub

    ''' <summary>
    ''' 获取里程、断面及中线类型对应表
    ''' </summary>
    ''' <param name="temp_mnt"></param>
    ''' <param name="mntlist"></param>
    ''' <remarks></remarks>
    Public Sub GetMntList(ByRef temp_mnt As ml_num_type, ByRef mntlist As List(Of ml_num_type))
        Dim currmil As Double
        Dim temping = paralist.StartMIL
        '获取里程断面基本信息
        If paralist.startNUM = paralist.endNUM Then
            Select Case paralist.Hmidline(paralist.startNUM).LineType
                Case LineTypeList.TypeLINE
                    For currmil = temping To paralist.EndMIL Step paralist.dist_L
                        temp_mnt = New ml_num_type()
                        temp_mnt.type = 0
                        temp_mnt.ml = currmil
                        temp_mnt.num = paralist.startNUM
                        mntlist.Add(temp_mnt)
                    Next
                Case LineTypeList.TypeCIRCLE
                    For currmil = temping To paralist.EndMIL Step paralist.dist_C
                        temp_mnt = New ml_num_type()
                        temp_mnt.type = 1
                        temp_mnt.ml = currmil
                        temp_mnt.num = paralist.startNUM
                        mntlist.Add(temp_mnt)
                    Next
                Case LineTypeList.TypeSUPERCIRCLE
                    For currmil = temping To paralist.EndMIL Step paralist.dist_SC
                        temp_mnt = New ml_num_type()
                        temp_mnt.type = 2
                        temp_mnt.ml = currmil
                        temp_mnt.num = paralist.startNUM
                        mntlist.Add(temp_mnt)
                    Next
            End Select
        Else

            For i = paralist.startNUM To paralist.endNUM
                Select Case paralist.Hmidline(i).LineType
                    Case LineTypeList.TypeLINE
                        If currmil < paralist.Hmidline(i).endm Then
                            For currmil = temping To paralist.Hmidline(i).endm Step paralist.dist_L
                                If currmil > paralist.EndMIL Then
                                    Exit For
                                End If
                                temp_mnt = New ml_num_type()
                                temp_mnt.type = 0
                                temp_mnt.ml = currmil
                                temp_mnt.num = i
                                mntlist.Add(temp_mnt)
                            Next
                            temping = currmil
                            Continue For
                        Else
                            Continue For
                        End If
                    Case LineTypeList.TypeCIRCLE
                        If currmil < paralist.Hmidline(i).endm Then
                            For currmil = temping To paralist.Hmidline(i).endm Step paralist.dist_C
                                If currmil > paralist.EndMIL Then
                                    Exit For
                                End If
                                temp_mnt = New ml_num_type()
                                temp_mnt.type = 1
                                temp_mnt.ml = currmil
                                temp_mnt.num = i
                                mntlist.Add(temp_mnt)
                            Next
                            temping = currmil
                            Continue For
                        Else
                            Continue For
                        End If
                    Case Else
                        If currmil < paralist.Hmidline(i).endm Then
                            For currmil = temping To paralist.Hmidline(i).endm Step paralist.dist_SC
                                If currmil > paralist.EndMIL Then
                                    Exit For
                                End If
                                temp_mnt = New ml_num_type()
                                temp_mnt.type = 2
                                temp_mnt.ml = currmil
                                temp_mnt.num = i
                                mntlist.Add(temp_mnt)
                            Next
                            temping = currmil
                            Continue For
                        Else
                            Continue For
                        End If
                End Select
            Next

        End If
    End Sub

    Private Sub Cancel_Click(sender As System.Object, e As System.EventArgs) Handles Cancel.Click
        Me.Parent = Nothing
    End Sub
    ''' <summary>
    ''' 导入自定义里程列表
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub importMIL_Click(sender As System.Object, e As System.EventArgs) Handles importMIL.Click
        Dim milfilename = DataAccess.importMil()
        If milfilename IsNot Nothing Then
            Me.Millist = FILEHelper.readMIL(milfilename)
            If Me.Millist.Count > 0 Then
                Me.flag = 1
            End If
        End If
    End Sub
End Class
''' <summary>
''' 结构体，界面解析参数
''' </summary>
''' <remarks></remarks>
Public Structure prepara
    ''' <summary>
    ''' 平曲线直线部分
    ''' </summary>
    ''' <remarks></remarks>
    Public numHL_L As Integer
    ''' <summary>
    ''' 平曲线圆曲线部分
    ''' </summary>
    ''' <remarks></remarks>
    Public numHL_C As Integer
    ''' <summary>
    ''' 平曲线缓和曲线部分
    ''' </summary>
    ''' <remarks></remarks>
    Public numHL_SC As Integer
    ''' <summary>
    ''' 竖曲线变坡点
    ''' </summary>
    ''' <remarks></remarks>
    Public numVL_BP As Integer
    ''' <summary>
    ''' 竖曲线凹曲线
    ''' </summary>
    ''' <remarks></remarks>
    Public numVL_AO As Integer
    ''' <summary>
    ''' 竖曲线凸曲线
    ''' </summary>
    ''' <remarks></remarks>
    Public numVL_TU As Integer
    ''' <summary>
    ''' 断面总数
    ''' </summary>
    ''' <remarks></remarks>
    Public numSE_AllS As Integer
    ''' <summary>
    ''' 直线部分断面总数
    ''' </summary>
    ''' <remarks></remarks>
    Public numSE_LS As Integer
    ''' <summary>
    ''' 圆曲线部分断面总数
    ''' </summary>
    ''' <remarks></remarks>
    Public numSE_CS As Integer
    ''' <summary>
    ''' 缓和曲线部分断面总数
    ''' </summary>
    ''' <remarks></remarks>
    Public numSE_SCS As Integer

End Structure
''' <summary>
''' 结构体，里程、断面、中线类型对应表
''' </summary>
''' <remarks></remarks>
Public Structure ml_num_type
    Public ml As Double
    Public num As Integer
    Public type As Integer
End Structure

